<template>
    <!-- 搜索工作栏 -->
    <ContentWrap>
        <el-form ref="queryFormRef" :inline="true" :model="queryParams" class="-mb-15px" label-width="68px">
            <el-form-item label="拼团名称" prop="combinationName">
                <el-input v-model="queryParams.combinationName" clearable placeholder="请输入拼团名称" />
            </el-form-item>
            <el-form-item>
                <el-button @click="handleQuery">
                    <Icon class="mr-5px" icon="ep:search" />
                    搜索
                </el-button>
                <el-button @click="resetQuery">
                    <Icon class="mr-5px" icon="ep:refresh" />
                    重置
                </el-button>
            </el-form-item>
        </el-form>
    </ContentWrap>
    <!-- 分页列表数据展示 -->
    <ContentWrap>
        <el-table v-loading="loading" :data="pageList">
            <el-table-column align="center" label="拼团ID" prop="combinationApplyId" min-width="50" />
            <el-table-column align="center" label="拼团名称" prop="combinationName" min-width="100" />
            <el-table-column align="center" label="团长" prop="leader" min-width="100" />
            <el-table-column :formatter="dateFormatter" align="center" label="拼团时间" prop="combinationTime" min-width="100" />
            <el-table-column align="center" label="地址" prop="address" />
            <el-table-column align="center" fixed="right" label="操作" width="150">
                <template #default="scope">
                    <el-button v-hasPermi="['promotion:combination-record:query']" link type="primary" @click="handleChange(scope.row)">
                        排课
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <Pagination v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNo" :total="total" @pagination="getList" />
    </ContentWrap>
    <!-- 排课表单弹窗 -->
    <CourseSchedulingForm ref="formRef" @success="getList" />
</template>
<script lang="ts" setup>
import CourseSchedulingForm from './CourseSchedulingForm.vue'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter, defaultShortcuts } from '@/utils/formatTime'
import * as SchedulingApi from '@/api/mall/promotion/combination/scheduling'

defineOptions({ name: 'PromotionSchedulingRecord' })

const queryParams = ref({
    status: undefined, // 拼团状态
    createTime: undefined, // 创建时间
    pageSize: 10,
    pageNo: 1
})
const queryFormRef = ref() // 搜索的表单
const formRef = ref() // 排课表单 Ref
const loading = ref(true) // 列表的加载中
const total = ref(0) // 总记录数
const pageList = ref < SchedulingApi.SchedulingVO[] > ([]) // 分页数据
/** 查询列表 */
const getList = async () => {
    loading.value = true
    try {
        const data = await SchedulingApi.getSchedulingList(queryParams.value)
        pageList.value = data.list as SchedulingApi.SchedulingVO[]
        total.value = data.total
    } finally {
        loading.value = false
    }
}

/** 搜索按钮操作 */
const handleQuery = () => {
    queryParams.value.pageNo = 1
    getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
    queryFormRef.value.resetFields()
    handleQuery()
}

/** 排课 */
const handleChange = (row: SchedulingApi.SchedulingVO) => {
    formRef.value?.open(row);
}

/** 初始化 **/
onMounted(async () => {
    await getList()
})

</script>
